from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, func
from sqlalchemy.dialects.mysql import LONGTEXT
from models import Base
from models.db import BaseModel


class Toolkit(BaseModel):
    __tablename__ = "toolkit"

    id = Column(Integer, primary_key=True)
    name = Column(String(64), unique=True, index=True, nullable=False)
    type = Column(Integer, nullable=False)
    tags = Column(String(32))
    args = Column(LONGTEXT)
    desc = Column(Text)
    content = Column(LONGTEXT)
    executor = Column(String(32))
    exec_user = Column(String(32))
    workspace = Column(String(255))
    sort = Column(Integer)
    username = Column(String(32), nullable=False)


class ToolkitLog(Base):
    __tablename__ = "toolkit_history"

    id = Column(Integer, primary_key=True)
    tool_id = Column(Integer, nullable=False)
    tool_name = Column(String(64), nullable=False)
    create_time = Column(DateTime, nullable=False)
    username = Column(String(32), nullable=False)
    status = Column(Integer, nullable=False)
    content = Column(LONGTEXT, nullable=False)


class Cache(Base):
    __tablename__ = "cache"
    id = Column(Integer, primary_key=True)
    key = Column(String(32), nullable=False)
    data = Column(LONGTEXT, nullable=False)
    create_time = Column(DateTime, nullable=False)
    username = Column(String(32), nullable=False)


class Share(Base):
    __tablename__ = "toolkit_share"
    id = Column(Integer, primary_key=True)

    name = Column(String(255), nullable=False)
    share_id = Column(String(32), nullable=False)
    script_id = Column(Integer, nullable=False)
    args = Column(LONGTEXT)
    status = Column(Boolean, nullable=False, default=True)
    content = Column(LONGTEXT)

    create_time = Column(DateTime, server_default=func.now())
    username = Column(String(32), nullable=False)
